﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mani.Common.Security;
using RastinArgham.CRM.Business;
using Mani.Common;

namespace RastinArgham.CRM.Web
{
    public partial class PhotoExport : System.Web.UI.Page
    {
        public ISecurityManager securityManager { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (securityManager == null)
            {
                securityManager = new SecurityManager();
                securityManager.authProvider = new WebAuthorizationProvider();
            }

            if (!securityManager.IsActionPermitted("export_photos"))
                Response.Redirect("~/access_denied.aspx");
        }

        protected void btnDownload_Click(object sender, EventArgs e)
        {
            DateTime? StartDate = txtStartDate.Text.ToDateTime();
            DateTime? EndDate = txtEndDate.Text.ToDateTime();

            if (StartDate == null)
            {
                UIHelper.ClientAlert(this, "فرمت تاریخ شروع صحیح نمی باشد");
                return;
            }

            if (EndDate == null)
            {
                UIHelper.ClientAlert(this, "فرمت تاریخ پایان صحیح نمی باشد");
                return;
            }

            string url = ImageExport.ExportRange(StartDate.Value, EndDate.Value, "~/tmp/");

            Response.Redirect(url);
        }
    }
}